package com.lyz.util;

import java.io.UnsupportedEncodingException;


import org.apache.commons.codec.binary.Base64;

/**
 * 加密算法
 * @author luyongzhao
 *
 */
public class SecretUtil {
	
//	private static Base64 base64 = new Base64();
	
	/**
	 * url base64编码
	 * @param line
	 * @return
	 */
	public static String getBase64String(String line){
		if(line == null){
			return null;
		}

		byte[] bytes = null;
		try {
			bytes = line.getBytes("utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			return null;
		}
//		if(base64 == null){
//			System.out.println( ">>>>>>>>base64 is null!");
//			return null;
//		}
//		System.out.println( ">>>>>>>>>>>>>>+"+bytes.length);
		return new Base64().encodeAsString(bytes);
	}
	
	public static String getDecodeofBase64(String line){
		try {
			return new String(new Base64().decode(line),"utf-8");
		} catch (UnsupportedEncodingException e) {
			return null;
		}
	}
	
	public static void main(String args[]){
		System.out.println(SecretUtil.getDecodeofBase64("bW9kZWw9SFRDIE9uZSBYJm9lbT1BTSZ1c2VyQWdlbnQ9TW96aWxsYS81LjAgKExpbnV4OyBVOyBBbmRyb2lkIDQuMi4xOyB6aC1jbjsgSFRDIE9uZSBYIEJ1aWxkL0pPUDQwRCkgQXBwbGVXZWJLaXQvNTM0LjMwIChLSFRNTCwgbGlrZSBHZWNrbykgVmVyc2lvbi80LjAgTW9iaWxlIFNhZmFyaS81MzQuMzAmbWFjYWRkcmVzcz1hYTphMDoxMjowMDowMTo5MSZkZXZpY2VJRD01Y2I1MWM2NzA5YmRhODY0JmFiaT1hcm1lYWJpLXY3YSZhcHB2ZXJzaW9uPTQuNS4xJmxjZD0xMjgwKjcyMCZsbmc9JmFkZHI9JnR5cGU9dXNlcmRlYnVnJmlwY2l0eT0maW9zVmVyc2lvbj00LjIuMSZhbmRyb2lkX2lkPTVjYjUxYzY3MDliZGE4NjQmbmV0dHlwZT1XSUZJJnByb2Nlc3Nvcj1BUk12NyBQcm9jZXNzb3IgcmV2IDkgKHY3bCkmbGF0PSZ0YWdzPXRlc3Qta2V5cyZwbGF0Zm9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